package xin.yangshuai.fastjson01.hello;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;

import javax.validation.constraints.Future;
import java.util.ArrayList;
import java.util.List;

/**
 * Hello
 *
 * @author shuai
 * @date 2022/1/11
 */
public class Hello {

    private String a = "aa";
    private int b = 12;

    private List<Integer> list;

    {
        list = new ArrayList<>();
        list.add(123);
        list.add(456);
    }

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public List<Integer> getList() {
        return list;
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }

    public static void main(String[] args) {

        JSON.DEFAULT_PARSER_FEATURE |= Feature.OrderedField.getMask();

        Hello hello = new Hello();
//        String string = JSON.toJSONString(new Hello(), SerializerFeature.WriteClassName);
        String string = JSON.toJSONString(hello);
        System.out.println(string);
        ParserConfig.getGlobalInstance().setAutoTypeSupport(true);

        Hello hello1 = JSON.parseObject(string, hello.getClass());
        System.out.println(hello1);

        Hello parse = (Hello) JSON.parse(string);
//        parse1.getA();
//        parse1.getB();
//        parse1.getList();
    }
}
